package com.raincat.multimediapicker.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.raincat.multimediapicker.PickerActivity;

import java.io.Serializable;

public class PickerConfig implements Serializable {
    private static final long serialVersionUID = 1L;

    public final static int RESULT = 0x81;

    public int mode = 0;

    /**
     * 裁剪输出大小，默认300
     */
    int outputX = 300;
    int outputY = 300;

    int maxSize = 1024;

    /**
     * 图片选择数量，默认为1
     */
    int maxCount = 1;

    /**
     * 是否显示拍照
     */
    boolean showCameraOption = false;

    /**
     * 是否显示原图
     */
    boolean showOriginalOption = false;

    public PickerConfig asImagePick() {
        mode = 0;
        return this;
    }

    public PickerConfig asImageCrop() {
        mode = 1;
        return this;
    }

    public PickerConfig asVideoPick() {
        mode = 2;
        return this;
    }

    public PickerConfig asVideoPick(int maxSizeBaseMB) {
        mode = 2;
        this.maxSize = maxSizeBaseMB;
        return this;
    }

    public PickerConfig withMaxCount(int maxCount) {
        this.maxCount = maxCount;
        return this;
    }

    public PickerConfig showCameraOption() {
        showCameraOption = true;
        return this;
    }

    public PickerConfig showOriginalOption() {
        showOriginalOption = true;
        return this;
    }

    public PickerConfig withCropOutputSize(int width, int height) {
        outputX = width;
        outputY = height;
        return this;
    }

    public PickerConfig start(Context context) {
        if (mode < 2)
            ImageController.initController(this);
        else
            VideoController.initController(this);
        Intent intent = new Intent(context, PickerActivity.class);
        intent.putExtra("Config", this);
        ((Activity) context).startActivityForResult(intent, RESULT);
        ((Activity) context).overridePendingTransition(android.R.anim.fade_in, 0);
        return this;
    }

    public static void reset() {
        PickerConfig pickerConfig = new PickerConfig();
        ImageController.initController(pickerConfig);
        VideoController.initController(pickerConfig);
        ImageController.reset();
        VideoController.reset();
    }
}
